<template>

  <div>
    <el-form :inline="true" :model="form" class="custom-left-form">

      <el-form-item label="食源性报卡::医院机构" class="custom-label-item">
        <el-select v-model="queryParams.ID_ORG" placeholder="请选择机构" style="width: 200px">
          <el-option v-for="item in provinceOptions" :key="item.ID_ORG" :label="item.NA" :value="item.ID_ORG"/>
        </el-select>
      </el-form-item>

      <!-- 新增的姓名字段 -->
      <el-form-item label="姓名">
        <el-input v-model="search" placeholder="请输入姓名" @keydown.enter.native="queryEscalationStatusList"></el-input>
      </el-form-item>


      <el-date-picker
          v-model="dateTiemObj"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions">
      </el-date-picker>

      <el-form-item>
        <el-button type="success" @click="queryEscalationStatusList()">食源性报卡查询</el-button>
      </el-form-item>

    </el-form>

    <!--    <el-table-column fixed prop="FBRQ" label="发病时间"></el-table-column>  fixed属性是让某一个字段优先在左侧固定显示-->
    <el-table :data="tableData" style="width: 100%" :fit="true">
      <el-table-column min-width="180" fixed prop="BLBH" label="病例编号"></el-table-column>
      <el-table-column min-width="90" fixed prop="患者姓名" label="患者姓名"></el-table-column>
      <el-table-column min-width="90" prop="患者性别" label="患者性别"></el-table-column>
      <el-table-column min-width="100" prop="出生日期" label="出生日期" ></el-table-column>
      <el-table-column min-width="90" prop="患者职业" label="患者职业"></el-table-column>
      <el-table-column min-width="110" prop="联系电话" label="联系电话"></el-table-column>
      <el-table-column min-width="90" prop="是否住院" label="是否住院"></el-table-column>
      <el-table-column min-width="250" prop="患者工作单位或学校" label="患者工作单位或学校"></el-table-column>
      <el-table-column min-width="90" prop="患者属于" label="患者属于"></el-table-column>
      <el-table-column min-width="180" prop="发病时间" label="发病时间"></el-table-column>
      <el-table-column min-width="180" prop="就诊时间" label="就诊时间"></el-table-column>
      <el-table-column min-width="180" prop="死亡时间" label="死亡时间"></el-table-column>
      <el-table-column min-width="150" prop="现在住址_省市县" label="现在住址_省市县"></el-table-column>
      <el-table-column min-width="150" prop="现在住址_详细地址" label="现在住址_详细地址"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_食品名称" label="暴露信息_食品名称"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_食品分类" label="暴露信息_食品分类"></el-table-column>
      <el-table-column min-width="200" prop="暴露信息_加工或包装方式" label="暴露信息_加工或包装方式"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_食品品牌" label="暴露信息_食品品牌"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_进食场所" label="暴露信息_进食场所"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_购买场所" label="暴露信息_购买场所"></el-table-column>
      <el-table-column min-width="150" prop="进食地点_境内境外" label="进食地点_境内境外"></el-table-column>
      <el-table-column min-width="150" prop="进食地点_省市县" label="进食地点_省市县"></el-table-column>
      <el-table-column min-width="150" prop="进食地点_详细地址" label="进食地点_详细地址"></el-table-column>
      <el-table-column min-width="150" prop="购买地点_境内境外" label="购买地点_境内境外"></el-table-column>
      <el-table-column min-width="150" prop="购买地点_省市县" label="购买地点_省市县"></el-table-column>
      <el-table-column min-width="150" prop="购买地点_详细地址" label="购买地点_详细地址"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_进食人数" label="暴露信息_进食人数"></el-table-column>
      <el-table-column min-width="150" prop="暴露信息_进食时间" label="暴露信息_进食时间"></el-table-column>
      <el-table-column min-width="200" prop="暴露信息_他人是否发病" label="暴露信息_他人是否发病"></el-table-column>
      <el-table-column min-width="150" prop="症状腹泻_性状" label="症状腹泻_性状"></el-table-column>
      <el-table-column min-width="150" prop="症状腹泻_次数" label="症状腹泻_次数"></el-table-column>
      <el-table-column min-width="90" prop="症状_腹痛" label="症状_腹痛"></el-table-column>
      <el-table-column min-width="90" prop="症状_恶心" label="症状_恶心"></el-table-column>
      <el-table-column min-width="150" prop="症状呕吐_次数" label="症状呕吐_次数"></el-table-column>
      <el-table-column min-width="150" prop="症状发热_度数" label="症状发热_度数"></el-table-column>
      <el-table-column min-width="90" prop="症状_头痛" label="症状_头痛"></el-table-column>
      <el-table-column min-width="90" prop="症状_发绀" label="症状_发绀"></el-table-column>
      <el-table-column min-width="90" prop="症状_麻木" label="症状_麻木"></el-table-column>
      <el-table-column min-width="150" prop="症状_呼吸困难" label="症状_呼吸困难"></el-table-column>
      <el-table-column min-width="150" prop="症状_吞咽困难" label="症状_吞咽困难"></el-table-column>
      <el-table-column min-width="150" prop="症状_面色潮红" label="症状_面色潮红"></el-table-column>
      <el-table-column min-width="150" prop="症状_视物模糊" label="症状_视物模糊"></el-table-column>
      <el-table-column min-width="90" prop="症状_抽搐" label="症状_抽搐"></el-table-column>
      <el-table-column min-width="90" prop="症状_昏迷" label="症状_昏迷"></el-table-column>
      <el-table-column min-width="90" prop="其他名称" label="其他名称"></el-table-column>
      <el-table-column min-width="200" prop="诊断结论_急性胃肠炎" label="诊断结论_急性胃肠炎"></el-table-column>
      <el-table-column min-width="300" prop="诊断结论_其他食源性疾病" label="诊断结论_其他食源性疾病"></el-table-column>
      <el-table-column min-width="90" prop="检测结果" label="检测结果"></el-table-column>

      <el-table-column min-width="240"  prop="CZDW" label="操作单位"></el-table-column>
      <el-table-column min-width="140"  prop="CZYH" label="操作用户"></el-table-column>

      <el-table-column min-width="110" fixed prop="XJBL_CZZT" label="新建状态"></el-table-column>
      <el-table-column min-width="250" prop="XJBL_ZTMS" label="新建病例状态描述"></el-table-column>
      <el-table-column min-width="160" prop="XJBL_SCRQ" label="新建病例上传日期"></el-table-column>

      <el-table-column min-width="110" fixed prop="SB_SCZT" label="上报状态"></el-table-column>
      <el-table-column min-width="250" prop="SB_SCZTMS" label="病例上报状态描述"></el-table-column>
      <el-table-column min-width="160" prop="SB_SBRQ" label="病例上报日期"></el-table-column>
      <el-table-column min-width="250" prop="ID_REPORT" label="病例ID"></el-table-column>
      <el-table-column min-width="170" prop="ID_ORG_CD" label="ID_ORG_CD"></el-table-column>
      <el-table-column min-width="170" prop="BUSINESSTYPE" label="BUSINESSTYPE"></el-table-column>
      <el-table-column min-width="170" prop="WORKNUMBER" label="WORKNUMBER"></el-table-column>
      <el-table-column min-width="240" prop="TOKEN" label="TOKEN"></el-table-column>


      <el-table-column min-width="270" fixed="right" label="操作">
        <template slot-scope="scope">

          <div class="button-row">
            <el-button    type="text"  @click="loadFoodborneIllness(scope.row)">新建</el-button>
            <el-button    type="text"  @click="deleteFoodborneIllness(scope.row)">删除</el-button>
            <el-button    type="text"  @click="updateFoodborneIllness(scope.row)">上报</el-button>
            <el-button    type="text"  @click="recallFoodborneIllness(scope.row)">召回</el-button>
            <el-button    type="text"  @click="revokeFoodborneIllness(scope.row)">撤回</el-button>
            <el-button    type="text"  @click="searchUrl(scope.row)">编辑</el-button>

          </div>

        </template>
      </el-table-column>
    </el-table>

  </div>
</template>


<script>
import {queryHospitalList, queryEscalationStatusList,updateFoodborneIllness,loadFoodborneIllness,deleteFoodborneIllness,recallFoodborneIllness,revokeFoodborneIllness,searchUrl} from "@/views/sybk/sybk";
import {formatTiem} from "@/utils/utils";

export default {
  name: "sybkV",
  data: function () {

    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一年',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getFullYear() - 1);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      dateTiemObj: [],//日期数组

      data: {rowList: ''},
      queryParams: {ID_ORG: ''},
      provinceOptions: [],
      form: {},
      tableData: [],
      search: ''
    }

  },
  created() {
    this.provinceOptionsmeth()
    this.setDefaultDateRange()
  },
  methods: {


    //查询报卡详细信息
    searchUrl(data) {
      this.data.jgid = data.OrgId;
      console.log(data)
      console.log(this.data)
      searchUrl(data).then(response => {
        this.tableData = response.data;
       //console.log('11111' + response)
        //console.log('11111' + this.data)
         window.open(response, '_blank');
      } )

    },


    //食源性报卡新建病例
    loadFoodborneIllness(data) {
      this.data.jgid = data.OrgId;
      console.log(data)
      console.log(this.data)
      loadFoodborneIllness(data).then(response => {
        if (response.responseCode == 1) {
          this.queryParams.ID_ORG = response.data.JGID;
        }
      }).catch(error => {
        // 网络错误等异常处理
        this.$message.error('食源性新建病例异常!' || error);
      });
    },

    //食源性报卡删除病例
    deleteFoodborneIllness(data) {
      this.data.jgid = data.OrgId;
      deleteFoodborneIllness(data).then(response => {
        if (response.responseCode == 1) {
          this.queryParams.ID_ORG = response.data.JGID;
        }
      }).catch(error => {
        // 网络错误等异常处理
        this.$message.error('食源性删除病例异常!' || error);
      });
    },

    //食源性报卡申请召回病例
    recallFoodborneIllness(data) {
      this.data.jgid = data.OrgId;
      recallFoodborneIllness(data).then(response => {
        if (response.responseCode == 1) {
          this.queryParams.ID_ORG = response.data.JGID;
        }
      }).catch(error => {
        // 网络错误等异常处理
        this.$message.error('食源性召回病例异常!' || error);
      });
    },



    //食源性报卡申请撤回病例
    revokeFoodborneIllness(data) {
      this.data.jgid = data.OrgId;
      revokeFoodborneIllness(data).then(response => {
        if (response.responseCode == 1) {
          this.queryParams.ID_ORG = response.data.JGID;
        }
      }).catch(error => {
        // 网络错误等异常处理
        this.$message.error('食源性申请撤回病例异常!' || error);
      });
    },

    //食源性报卡上传
    updateFoodborneIllness(data) {
      console.log(data)
     // this.data.invoiceNumber = data.FPHM;
      //this.data.euDirect = '-1';
      this.data.jgid = data.OrgId;
     // this.data.medstoeid = data.idMedstCg;
      console.log(this.data)
      updateFoodborneIllness(data).then(response => {
        if (response.responseCode == 1) {
          this.queryParams.ID_ORG = response.data.JGID;
          //this.queryParams.invoiceNumber = response.data.YYFPHM;
         // this.queryInvoiceById(this.queryParams);
        }
      }).catch(error => {
        // 网络错误等异常处理
        this.$message.error('食源性报卡异常!' || error);
      });
    },

    setDefaultDateRange() {
      const endDate = new Date(); // 结束日期：今天
      const startDate = new Date();

      // 精确计算一年前（处理闰年等问题）
      startDate.setFullYear(endDate.getFullYear() - 1);
      // 设置默认值（两种格式任选其一）
      this.dateTiemObj = [startDate, endDate]; // Date 对象格式（推荐）
    },
    provinceOptionsmeth() {
      queryHospitalList().then(response => {
        if (response.code == 200) {
          this.provinceOptions = response.data;
        }
        // 设置默认选中第一个选项
        if (this.provinceOptions.length > 0) {
          this.queryParams.ID_ORG = '674dab0fd1bf390001ffbd40';/*默认显示玉溪市中医医院*/
          //this.queryParams.ID_ORG = this.provinceOptions[0].ID_ORG;
        }
      });
    },
    queryEscalationStatusList() {
      this.queryParams.startTiem = formatTiem(this.dateTiemObj[0]);
      this.queryParams.endTiem = formatTiem(this.dateTiemObj[1]);
      this.queryParams.NA_PATIENT = this.search;
      queryEscalationStatusList(this.queryParams).then(response => {
        if (response.responseCode == 1 ) {
          this.tableData = response.data;
        }
      });
    }
  }
}
</script>
